package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wms.domain.StockTransfer;
import com.ruoyi.wms.service.IStockTransferService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 库存调拨Controller
 *
 * @author ruoyi
 * @date 2025-10-24
 */
@Api(value = "库存调拨Controller", tags = "库存调拨Controller")
@RestController
@RequestMapping("/transfer")
public class StockTransferController extends BaseController {
    @Autowired
    private IStockTransferService stockTransferService;

    /**
     * 查询库存调拨列表
     */
    @RequiresPermissions("wms:transfer:list")
    @GetMapping("/list")
    public TableDataInfo list(StockTransfer stockTransfer) {
        startPage();
        List<StockTransfer> list = stockTransferService.selectStockTransferList(stockTransfer);
        return getDataTable(list);
    }


    /**
     * 获取库存调拨详细信息
     */
    @RequiresPermissions("wms:transfer:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(stockTransferService.selectStockTransferById(id));
    }

    /**
     * 修改库存调拨
     */
    @RequiresPermissions("wms:transfer:edit")
    @Log(title = "库存调拨", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockTransfer stockTransfer) {
        return toAjax(stockTransferService.updateStockTransfer(stockTransfer));
    }

    /**
     * 删除库存调拨
     */
    @RequiresPermissions("wms:transfer:remove")
    @Log(title = "库存调拨", businessType = BusinessType.DELETE)

    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String[] ids) {
        if (ids == null || ids.length == 0) {
            return error("未选中");
        }
        return toAjax(stockTransferService.deleteStockTransferByIds(ids));
    }

}
